package com.nowcoder.code.lcof;

public class JZ39 {

    public static void main(String[] args) {
        System.out.println(new JZ39().MoreThanHalfNum_Solution(new int[]{1, 2, 3, 2, 2, 2, 5, 4, 2}));

    }

    public int MoreThanHalfNum_Solution(int[] numbers) {
        int c = 0;
        int r = -1;

        for (int number : numbers) {
            if (c == 0 || r == number) {
                r = number;
                c++;
            } else {
                c--;
            }

        }
        return r;
    }

}
